﻿<div class="full_w">
	<div class="h_title">QUẢN LÝ CÂU HỎI</div>
	<h2>Ngân hàng câu hỏi</h2>
	<div class="n_error"><?php echo $flash_error; ?></div>
	<div class="n_ok"><?php echo $flash_ok; ?></div>
    <div class="cate-filter">
		<p style="color:#333;">Thuộc phần: <?php echo $dropdown; ?></p>
    </div>
	<div class="mybox">
	<table class="display" id="example">
		<thead>
			<tr>
				<th>ID</th>
				<th>Nội dung</th>
				<th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td></td>
				<td></td>
				<td></td>
                <td></td>
				<td></td>
				<td></td>
                <td></td>
                <td></td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<th>ID</th>
				<th>Nội dung</th>
				<th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
			</tr>
		</tfoot>
	</table>
	</div>
	<script>
		var oTable;
		var right_ans;
 
		/* Formating function for row details */
		function fnFormatDetails ( nTr )
		{
			var aData = oTable.fnGetData( nTr );
			var ques_id = aData[0];
			var url_a = '<?php echo site_url("managequestion/get_answer_by_question") ?>';
			url_a += '/' + ques_id;
			var sOut = "";
			$.ajax({
			  	type: "POST",
			  	url: url_a,
				async: false
			}).done(function( msg ) {
				var data = eval('(' + msg + ')');
				sOut = '<table class="details"">';
				sOut += '<tr class="1"><td width="5%">A.</td><td>' + data.aaData[0] + '</td></tr>';
				sOut += '<tr class="2"><td>B.</td><td>' + data.aaData[1] + '</td></tr>';
				sOut += '<tr class="3"><td>C.</td><td>' + data.aaData[2] + '</td></tr>';
				sOut += '<tr class="4"><td>D.</td><td>' + data.aaData[3] + '</td></tr>';
				sOut += '<tr><td colspan="2" style="font-weight:normal;" align="right">Tạo bởi <span class="highlight">' + aData[2] + 
					'</span> vào <span class="highlight">' + aData[3] +'</span> -  Chỉnh sửa lần cuối bởi <span class="highlight">' +
					aData[4] + '</span> vào <span class="highlight">' + aData[5] +  '</span> </td></tr>';
				sOut += '</table>';
				
				right_ans = aData[6];
				
				return sOut;
			});
			
			return sOut;
		}
		
		$('.cate-filter select').live('change', function() {
			var category_id = $('.cate-filter select option:selected').val();
			
			$('#example').dataTable().fnDestroy();
			var source = '<?php echo site_url("managequestion/listall/"); ?>';
			source += '/' + category_id;

			$('#example').dataTable({
				"bStateSave": true,
				"bProcessing": true,
				"sAjaxSource": source,
				"aoColumnDefs": [
							{ "bSearchable": false, "bVisible": false, "aTargets": [ 0,2,3,4,5,6 ] }
						],
				"sPaginationType": "full_numbers",
				"oLanguage": {
					"sUrl": "<?php echo base_url(); ?>js/vi_VN.txt"
				},
				"bDestroy": true,
				"bRetrieve": true
			  });	
		});
		$(document).ready(function() {
			
			$('.cate-filter select').prepend("<option value='0' selected='selected'>Tất cả</option>");
			
			$('#example').dataTable({
				"bStateSave": true,
				"bProcessing": true,
				"sAjaxSource": '<?php echo site_url("managequestion/listall/0"); ?>',
				"aoColumnDefs": [
							{ "bSearchable": false, "bVisible": false, "aTargets": [ 0,2,3,4,5,6 ] }
						],
				"sPaginationType": "full_numbers",
				"oLanguage": {
					"sUrl": "<?php echo base_url(); ?>js/vi_VN.txt"
				},
				"bDestroy": true,
				"bRetrieve": true
			  });
			  
			  oTable = $('#example').dataTable();
			  
			  $('#example tbody td img.details-open').live( 'click', function () {
				var nTr = $(this).parents('tr')[0];
				if ( oTable.fnIsOpen(nTr) )
				{
					/* This row is already open - close it */
					//this.src = "../examples_support/details_open.png";
					oTable.fnClose( nTr );
					
				}
				else
				{
					/* Open this row */
					//this.src = "../examples_support/details_close.png";
					oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
					var tr_ans = 'tr.' + right_ans;
					$($(this).parent().parent().next('tr').find(tr_ans)).addClass('rightans');
				}
			} );
			  
			  
			  
			//$(".ajax").fancybox({type: 'ajax'});
		});
		function del_confirm()
	  	{
			return confirm('Bạn có chắc chắn muốn xóa câu hỏi này?');
	  	}
	</script>
</div>
